/*
题目链接 : https://leetcode.cn/problems/the-number-of-beautiful-subsets/description/?envType=daily-question&envId=2025-03-07
*/

//题解代码 : 
class Solution {
public:
    int beautifulSubsets(vector<int>& nums, int k) {
        int n = nums.size();
        int ans = 0;
        int mask = 0;
        auto dfs = [&](auto&& dfs,int i)->void{
            if(i==n){
              ans+= mask!=0;
              return;  
            }
            dfs(dfs,i+1);
            for(int j=0;j<i;++j){
                if((mask>>j)&1 && abs(nums[j]-nums[i])==k){
                    return;
                }
            }
            mask |= (1<<i);
            dfs(dfs,i+1);
            mask ^= (1<<i);
        };
        dfs(dfs,0);
        return ans;
    }
};
